package com.lrs.java.j2se_advanced.codec;

public class HexConvertion {

	public static void main(String[] args) {
		//二进制转十进制
//		print((byte)Integer.valueOf("10111111",2).intValue());
		
		
		String hex = "0081271012648410FD000054989680000000D3EA80";
		print(hex2Byte(hex));
	}
	
	
	public static String hex2Byte(String hex) {
		StringBuilder builder = new StringBuilder();
		
		byte[] bytes = new byte[hex.length()/2];
		for(int i=0; i<bytes.length; i++) {
			String str = hex.substring(i*2, (i+1)*2);
			String byteStr = Integer.toBinaryString(Integer.valueOf(str, 16));
			if(byteStr.length() < 8) {
				byteStr = "00000000".substring(0, 8-byteStr.length()) + byteStr;
			}
			builder.append(byteStr);
		}
		return builder.toString();
	}
	
	
	public static void print(Object obj) {
		System.out.println(obj);
	}
	
}
